package com.example.wendao.view.ui.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

import com.example.wendao.App;
import com.example.wendao.R;
import com.example.wendao.model.entity.User;
import com.example.wendao.viewmodel.UserViewModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class MessageFragment extends Fragment {

    private TextView text_like;
    private TextView text_talk;
    private TextView text_fans;
    private UserViewModel userViewModel = null;
    private User user;
    public MessageFragment() {}


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_message, container, false);
        text_like = view.findViewById(R.id.text_like111);
        text_talk = view.findViewById(R.id.text_talk111);
        text_fans = view.findViewById(R.id.text_fans111);

        userViewModel = new ViewModelProvider(App.getInstance()).get(UserViewModel.class);

        user = userViewModel.getCurrentUser();  // 必须要登录才能使用，判空操作

        // 点赞点击事件
        text_like.setOnClickListener(v->{
            if (userViewModel.userLoggedIn()){
                Bundle bundle=new Bundle();
                bundle.putInt("userid",user.getUserId());

                  //在此修改跳转的页面
                 Navigation.findNavController(v).navigate(R.id.fragment_infoagree_paging1,bundle);

            } else {
                Toast.makeText(getContext(), "请登录后查看", Toast.LENGTH_SHORT).show();
            }
        });

        text_talk.setOnClickListener(v -> {
            if (userViewModel.userLoggedIn()){
                Bundle bundle=new Bundle();
                bundle.putInt("userid",user.getUserId());
            //在此修改跳转的页面
            Navigation.findNavController(v).navigate(R.id.fragment_infomessage_paging1,bundle);
            } else {
                Toast.makeText(getContext(), "请登录后查看", Toast.LENGTH_SHORT).show();
            }
        });
        text_fans.setOnClickListener(v->{
            if (userViewModel.userLoggedIn()){
                Bundle bundle=new Bundle();
                bundle.putInt("userid",user.getUserId());
                //此处无需修改，直接跳到该页面即可
                Navigation.findNavController(v).navigate(R.id.fragment_fans,bundle);
            } else {
                Toast.makeText(getContext(), "请登录后查看", Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }

}

